package top.happylaishop.shop.controller.backend;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.happylaishop.shop.dto.CategoryDto;
import top.happylaishop.shop.service.CategoryService;
import top.happylaishop.shop.service.CommonService;
import top.happylaishop.shop.utils.resp.BaseResponse;
import top.happylaishop.shop.utils.resp.RestResponse;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/manage/category")
public class CategoryManageController {

    @Autowired
    private CategoryService categoryService;
    @Autowired
    private CommonService commonService;

    @PostMapping("add")
    public BaseResponse add(@RequestBody CategoryDto categoryDto) {
        return categoryService.add(categoryDto, commonService.getCurrentUserInfo());
    }

    @PostMapping("update")
    public BaseResponse update(@RequestBody CategoryDto categoryDto) {
        return categoryService.update(categoryDto, commonService.getCurrentUserInfo());
    }

    @GetMapping("/detail/{categoryId}")
    public RestResponse listChildrenParallelCategory(Integer categoryId) {
        return categoryService.listChildrenParallelCategory(categoryId);
    }

    @GetMapping("/detailTree/{categoryId}")
    public RestResponse listCategoryAndDeepChildrenCategory(Integer categoryId) {
        return categoryService.listCategoryAndChildrenById(categoryId);
    }
}
